﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SES.CMS.BL;
using SES.CMS.DO;

namespace SES.CMS.AdminCP.PageUC
{
    public partial class ucFaqAnswer : System.Web.UI.UserControl
    {
        cmsHoiDapDO hoidapDO = new cmsHoiDapDO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["FaqID"] != null)
            {
                hoidapDO.HoiDapID = int.Parse(Request.QueryString["FaqID"].ToString());
                InitForm();
            }
        }
        // Save_Button
        long i;
        protected void btSave_Click(object sender, EventArgs e)
        {
            SetObject();
            if (hoidapDO.HoiDapID <= 0)
            {
                i = new cmsHoiDapBL().Insert(hoidapDO);
                Functions.Alert("Thêm mới thành công", "Default.aspx?Page=FAQ");
            }
            else
            {
                i = new cmsHoiDapBL().Update(hoidapDO);
                i = hoidapDO.HoiDapID;
                Functions.Alert("Cập nhật thành công", "Default.aspx?Page=FAQ");
            }

        }
        protected void InitForm()
        {
            hoidapDO = new cmsHoiDapBL().Select(hoidapDO);
            txtTenNguoiHoi.Text = hoidapDO.HoTenNguoiHoi;
            txtEmail.Text = hoidapDO.Email;
            txtNgayHoi.Text = hoidapDO.NgayHoi.ToShortDateString();
            txtCauHoi.Text = hoidapDO.CauHoi;
            txtCauTraLoi.Text = hoidapDO.CauTraLoi;
            txtNguoiTraLoi.Text = hoidapDO.NguoiTraLoi;
            cbDaTraLoi.Checked = hoidapDO.DaTraLoi;
            cbHienThi.Checked = hoidapDO.HienThi;

        }
        // SetObject()
        protected void SetObject()
        {
            hoidapDO.HoTenNguoiHoi = txtTenNguoiHoi.Text;
            hoidapDO.Email = txtEmail.Text;
            hoidapDO.CauHoi = txtCauHoi.Text;
            hoidapDO.CauTraLoi = txtCauTraLoi.Text;
            hoidapDO.NguoiTraLoi = txtNguoiTraLoi.Text;
            hoidapDO.NgayHoi = Convert.ToDateTime(txtNgayHoi.Text);
            hoidapDO.NgayTraLoi = DateTime.Now;
            hoidapDO.HienThi = cbHienThi.Checked;
            hoidapDO.DaTraLoi = cbDaTraLoi.Checked;

        
        }
    }
}